

@EXTERNAL FUNCTION getValue : DINT
    VAR_INPUT
        n : REF_TO STRING;
        t : REF_TO STRING;
        d : REF_TO STRING;
    END_VAR
END_FUNCTION


@EXTERNAL FUNCTION setValue : DINT
    VAR_INPUT
        n : REF_TO STRING;
        t : REF_TO STRING;
        d : REF_TO STRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION out : DINT
    VAR_INPUT
        t : REF_TO STRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outW : DINT
    VAR_INPUT
        t : REF_TO WSTRING;
    END_VAR
END_FUNCTION

@EXTERNAL FUNCTION outInt : DINT
    VAR_INPUT
        n : DINT;
    END_VAR
END_FUNCTION

TYPE _StructOfStudent: STRUCT
    name: STRING[255];
    age: INT;
    tt: DINT;
END_STRUCT END_TYPE


FUNCTION main : DINT
    VAR
        P : STRING := '';
        Q : WSTRING := "";
        R : CHAR := 'A';
		C : DINT := 0;
		ty_date : DATE := 1666000343;
		
		
		
        int_array : ARRAY[0..2] OF DINT;
        bool_array : ARRAY[0..2] OF BOOL;


        StructOfStudent : _StructOfStudent;
        pp : REF_TO STRING;
	END_VAR

    setValue(ADR('pp'),ADR('POINTER'),ADR(p));

    

    out(ADR('STRING Test:\n'));
    getValue(ADR('P'),ADR('STRING'),ADR(P));
    out(ADR(P));
    setValue(ADR('P'),ADR('STRING'),ADR('hello st !!'));
    getValue(ADR('P'),ADR('STRING'),ADR(P));
    out(ADR(P));
    out(ADR('=============================='));

    out(ADR('WSTRING Test:\n'));
    getValue(ADR('Q'),ADR('WSTRING'),ADR(Q));
    outW(ADR(Q));
    setValue(ADR('Q'),ADR('WSTRING'),ADR("Q hello st !!"));
    getValue(ADR('Q'),ADR('WSTRING'),ADR(Q));
    outW(ADR(Q));
    out(ADR('=============================='));
    out(ADR('CHAR Test:\n'));
    getValue(ADR('R'),ADR('CHAR'),ADR(R));
    outInt(R);
    setValue(ADR('R'),ADR('CHAR'),ADR('N'));
    getValue(ADR('R'),ADR('CHAR'),ADR(R));
    outInt(R);
    out(ADR('=============================='));

    out(ADR('Array_INT Test:\n'));
    out(ADR('Array_INT getValue:'));
    getValue(ADR('Y'),ADR('Array_INT'),ADR(int_array));
    outInt(int_array[0]);
    outInt(int_array[1]);
    out(ADR('Array_INT setValue:'));
    int_array[0] := 6;
    int_array[1] := 106;
    setValue(ADR('Y'),ADR('Array_INT'),ADR(int_array));
    int_array[0] := 0;
    int_array[1] := 0;
    getValue(ADR('Y'),ADR('Array_INT'),ADR(int_array));
    outInt(int_array[0]);
    outInt(int_array[1]);


	out(ADR('=============================='));
    out(ADR('DATE Test:\n'));
    getValue(ADR('ty_date'),ADR('DATE'),ADR(ty_date));
    outInt(ty_date);
	ty_date := 1677000343;
    setValue(ADR('ty_date'),ADR('DATE'),ADR(ty_date));
    getValue(ADR('ty_date'),ADR('DATE'),ADR(ty_date));
    outInt(ty_date);
    out(ADR('=============================='));
	
	
    out(ADR('DINT Test:\n'));
    getValue(ADR('C'),ADR('DINT'),ADR(C));
    outInt(C);
	
	C := 123456;
    setValue(ADR('C'),ADR('DINT'),ADR(C));
    getValue(ADR('C'),ADR('DINT'),ADR(C));
    outInt(C);
    out(ADR('=============================='));
	

    out(ADR('Array_BOOL Test:\n'));
    out(ADR('Array_BOOL getValue:'));
    getValue(ADR('Z'),ADR('Array_BOOL'),ADR(bool_array));
    outInt(bool_array[0]);
    outInt(bool_array[1]);
    out(ADR('Array_BOOL setValue:'));
    bool_array[0] := TRUE;
    bool_array[1] := TRUE;
    setValue(ADR('Z'),ADR('Array_BOOL'),ADR(bool_array));
    bool_array[0] := FALSE;
    bool_array[1] := FALSE;
    getValue(ADR('Z'),ADR('Array_BOOL'),ADR(bool_array));
    outInt(bool_array[0]);
    outInt(bool_array[1]);
    out(ADR('=============================='));


    out(ADR('StructOfStudent Test:\n'));
    out(ADR('StructOfStudent getValue:\n'));
    StructOfStudent.name := '';
    StructOfStudent.age := 0;
    StructOfStudent.tt := 0;
    getValue(ADR('StructOfStudent'),ADR('STRUCT'),ADR(StructOfStudent));
    out(ADR(StructOfStudent.name));
    outInt(StructOfStudent.age);
    outInt(StructOfStudent.tt);

    out(ADR('StructOfStudent setValue:\n'));
    StructOfStudent.name := 'zs';
    StructOfStudent.age := 18;
    StructOfStudent.tt := 120;
    setValue(ADR('StructOfStudent'),ADR('STRUCT'),ADR(StructOfStudent));
    StructOfStudent.name := '';
    StructOfStudent.age := 0;
    StructOfStudent.tt := 0;
    getValue(ADR('StructOfStudent'),ADR('STRUCT'),ADR(StructOfStudent));
    out(ADR(StructOfStudent.name));
    outInt(StructOfStudent.age);
    outInt(StructOfStudent.tt);


    out(ADR('==============ptr========='));
    getValue(ADR('pp'),ADR('POINTER'),ADR(pp));
    out(pp);

END_FUNCTION
